package com.ruoyi.dgdData.service.impl;

import com.deepoove.poi.data.PictureRenderData;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.*;
import com.ruoyi.dgdData.domain.pad.DgdTaskReqDTO;
import com.ruoyi.dgdData.domain.pad.DgdTaskRespDTO;
import com.ruoyi.dgdData.domain.pad.DgdTreeDataItemDto;
import com.ruoyi.dgdData.domain.plat.*;
import com.ruoyi.dgdData.domain.report.DgdReportData;
import com.ruoyi.dgdData.service.*;
import com.ruoyi.task.domain.entity.DataTaskEntity;
import com.ruoyi.task.service.IDataTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;


/**
 * 单轨吊面温度数据Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-28
 */
@Service
public class DataDgdServiceImpl implements IDataDgdService
{

    @Autowired
    private IDataTaskService dataTaskService;

    @Autowired
    private IDataDgdBmwdService bmwdService;

    @Autowired
    private IDataDgdHjService hjService;

    @Autowired
    private IDataDgdHshlService hshlService;

    @Autowired
    private IDataDgdJdService jdService;

    @Autowired
    private IDataDgdKdshjService kdshjService;

    @Autowired
    private IDataDgdKzxshService kzxshService;

    @Autowired
    private IDataDgdLqshService lqshService;

    @Autowired
    private IDataDgdMzxxService mzxxService;

    @Autowired
    private IDataDgdPqwdService pqwdService;

    @Autowired
    private IDataDgdQylService qylService;

    @Autowired
    private IDataDgdSdService sdService;

    @Autowired
    private IDataDgdYlService ylService;

    @Autowired
    private IDataDgdZhdlService zhdlService;

    /**
     * 详情数据
     *
     * @param dataTaskId
     * @return
     * @throws ExecutionException
     * @throws InterruptedException
     */
    @Override
    public DgdTaskReqDTO getDetailDgd(Long dataTaskId) throws ExecutionException, InterruptedException {
        long startTime = System.currentTimeMillis();
        //测试数据基本信息
        Future<DataTaskEntity> taskFuture = dataTaskService.selectDataTask(dataTaskId);
        //表面温度
        Future<List<DataDgdBmwd>> bmwdListFuture = bmwdService.selectDataDgdBmwdByDataTaskId(dataTaskId);
        //环境
        Future<List<DataDgdHj>> hjListFuture = hjService.selectDataDgdHjByDataTaskId(dataTaskId);
        //回绳轮预张紧力
        Future<List<DataDgdHshl>> hshlListFuture = hshlService.selectDataDgdHshlByDataTaskId(dataTaskId);
        //角度
        Future<List<DataDgdJd>> jdListFuture = jdService.selectDataDgdJdByDataTaskId(dataTaskId);
        //空动时间
        Future<List<DataDgdKdshj>> kdshjListFuture = kdshjService.selectDataDgdKdshjByDataTaskId(dataTaskId);
        //空载向上制动减速度
        Future<List<DataDgdKzxsh>> kzxshListFuture = kzxshService.selectDataDgdKzxshByDataTaskId(dataTaskId);
        //冷却水
        Future<List<DataDgdLqsh>> lqsListFuture = lqshService.selectDataDgdLqshByDataTaskId(dataTaskId);
        //满载向下制动距离
        Future<List<DataDgdMzxx>> mzxxListFuture = mzxxService.selectDataDgdMzxxByDataTaskId(dataTaskId);
        //排气温度
        Future<List<DataDgdPqwd>> pqwdListFuture = pqwdService.selectDataDgdPqwdByDataTaskId(dataTaskId);
        //牵引力
        Future<List<DataDgdQyl>> qylListFuture = qylService.selectDataDgdQylByDataTaskId(dataTaskId);
        //速度
        Future<List<DataDgdSd>> sdListFuture = sdService.selectDataDgdSdByDataTaskId(dataTaskId);
        //压力
        Future<List<DataDgdYl>> ylListFuture = ylService.selectDataDgdYlByDataTaskId(dataTaskId);
        //制动力
        Future<List<DataDgdZhdl>> zhdlListFuture = zhdlService.selectDataDgdZhdlByDataTaskId(dataTaskId);
        //添加到集合对象中
        List<Future<?>> futureList = new ArrayList<>();
        futureList.add(taskFuture);
        futureList.add(bmwdListFuture);
        futureList.add(hjListFuture);
        futureList.add(hshlListFuture);
        futureList.add(jdListFuture);
        futureList.add(kdshjListFuture);
        futureList.add(kzxshListFuture);
        futureList.add(lqsListFuture);
        futureList.add(mzxxListFuture);
        futureList.add(pqwdListFuture);
        futureList.add(qylListFuture);
        futureList.add(sdListFuture);
        futureList.add(ylListFuture);
        futureList.add(zhdlListFuture);
        // 从future提取所有数据
        DgdTaskRespDTO dgdTaskRespDTO = new DgdTaskRespDTO();
        for (Future<?> future : futureList) {
            while (true) {
                if (taskFuture.isDone() && !taskFuture.isCancelled()) {
                    // 获取结果
                    Object resultObject = future.get();
                    // 任务数据
                    if (resultObject instanceof DataTaskEntity) {
                        dgdTaskRespDTO.setDataTaskEntity((DataTaskEntity) resultObject);
                    }
                    if (resultObject instanceof java.util.List) {
                        List<Object> resultList = (List<Object>) resultObject;
                        if (!resultList.isEmpty()) {
                            Object item = resultList.get(0);
                            //测试任务类型获取数据
                            if (item instanceof DataDgdBmwd) {
                                dgdTaskRespDTO.setBmwdEntityList(ListUtils.castList(resultList, DataDgdBmwd.class));
                            }
                            if (item instanceof DataDgdHj) {
                                dgdTaskRespDTO.setHjTestList(ListUtils.castList(resultList, DataDgdHj.class));
                            }
                            if (item instanceof DataDgdHshl) {
                                dgdTaskRespDTO.setHshlyzhjlEntityList(ListUtils.castList(resultList, DataDgdHshl.class));
                            }
                            if (item instanceof DataDgdJd) {
                                dgdTaskRespDTO.setJdTestList(ListUtils.castList(resultList, DataDgdJd.class));
                            }
                            if (item instanceof DataDgdKdshj) {
                                dgdTaskRespDTO.setKdshjEntityList(ListUtils.castList(resultList, DataDgdKdshj.class));
                            }
                            if (item instanceof DataDgdKzxsh) {
                                dgdTaskRespDTO.setKzxshEntityList(ListUtils.castList(resultList, DataDgdKzxsh.class));
                            }
                            if (item instanceof DataDgdLqsh) {
                                dgdTaskRespDTO.setLqshwdEntityList(ListUtils.castList(resultList, DataDgdLqsh.class));
                            }
                            if (item instanceof DataDgdMzxx) {
                                dgdTaskRespDTO.setMzxxEntityList(ListUtils.castList(resultList, DataDgdMzxx.class));
                            }
                            if (item instanceof DataDgdPqwd) {
                                dgdTaskRespDTO.setPqwdEntityList(ListUtils.castList(resultList, DataDgdPqwd.class));
                            }
                            if (item instanceof DataDgdQyl) {
                                dgdTaskRespDTO.setQylEntityList(ListUtils.castList(resultList, DataDgdQyl.class));
                            }
                            if (item instanceof DataDgdSd) {
                                dgdTaskRespDTO.setSdTestList(ListUtils.castList(resultList, DataDgdSd.class));
                            }
                            if (item instanceof DataDgdYl) {
                                dgdTaskRespDTO.setYlEntityList(ListUtils.castList(resultList, DataDgdYl.class));
                            }
                            if (item instanceof DataDgdZhdl) {
                                dgdTaskRespDTO.setZhdlEntityList(ListUtils.castList(resultList, DataDgdZhdl.class));
                            }
                        }
                    }
                    break;
                } else {
                    // 轮询查询结果
                    Thread.sleep(10);
                }
            }
        }
        //目录结构拼接
        List<DgdTreeDataItemDto> treeDataList = new ArrayList<>();
        //速度测试
        if (null != dgdTaskRespDTO.getSdTestList() && !dgdTaskRespDTO.getSdTestList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("sdTestList");
            dgdTaskRespDTO.getSdTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("sdTestList");
            treeDataList.add(treeDataItemDto);
        }
        //角度测试
        if (null != dgdTaskRespDTO.getJdTestList() && !dgdTaskRespDTO.getJdTestList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("jdTestList");
            dgdTaskRespDTO.getJdTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("jdTestList");
            treeDataList.add(treeDataItemDto);
        }
        //空动时间测试
        if (null != dgdTaskRespDTO.getKdshjEntityList() && !dgdTaskRespDTO.getKdshjEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("kdshjEntityList");
            dgdTaskRespDTO.getKdshjEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("kdshjEntityList");
            treeDataList.add(treeDataItemDto);
        }
        // 满载向下制动距离测试
        if (null != dgdTaskRespDTO.getMzxxEntityList() && !dgdTaskRespDTO.getMzxxEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("mzxxEntityList");
            dgdTaskRespDTO.getMzxxEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("mzxxEntityList");
            treeDataList.add(treeDataItemDto);
        }
        // 空载向上制动减速度测试
        if (null != dgdTaskRespDTO.getKzxshEntityList() && !dgdTaskRespDTO.getKzxshEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("kzxshEntityList");
            dgdTaskRespDTO.getKzxshEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("kzxshEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //牵引力测试
        if (null != dgdTaskRespDTO.getQylEntityList() && !dgdTaskRespDTO.getQylEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("qylEntityList");
            dgdTaskRespDTO.getQylEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("qylEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //制动力测试
        if (null != dgdTaskRespDTO.getZhdlEntityList() && !dgdTaskRespDTO.getZhdlEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("zhdlEntityList");
            dgdTaskRespDTO.getZhdlEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("zhdlEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //回绳轮预张紧力测试
        if (null != dgdTaskRespDTO.getHshlyzhjlEntityList() && !dgdTaskRespDTO.getHshlyzhjlEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("hshlyzhjlEntityList");
            dgdTaskRespDTO.getHshlyzhjlEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("hshlyzhjlEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //排气温度测试
        if (null != dgdTaskRespDTO.getPqwdEntityList() && !dgdTaskRespDTO.getPqwdEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("pqwdEntityList");
            dgdTaskRespDTO.getPqwdEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("pqwdEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //表面温度测试
        if (null != dgdTaskRespDTO.getBmwdEntityList() && !dgdTaskRespDTO.getBmwdEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("bmwdEntityList");
            dgdTaskRespDTO.getBmwdEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("bmwdEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //冷却水温度测试
        if (null != dgdTaskRespDTO.getLqshwdEntityList() && !dgdTaskRespDTO.getLqshwdEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("lqshwdEntityList");
            dgdTaskRespDTO.getLqshwdEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("lqshwdEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //压力测试
        if (null != dgdTaskRespDTO.getYlEntityList() && !dgdTaskRespDTO.getYlEntityList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("ylEntityList");
            dgdTaskRespDTO.getYlEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("ylEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //环境测试
        if (null != dgdTaskRespDTO.getHjTestList() && !dgdTaskRespDTO.getHjTestList().isEmpty()) {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("hjTestList");
            dgdTaskRespDTO.getHjTestList().forEach(item-> treeDataItemDto.getTestItemList().add(new DgdTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            DgdTreeDataItemDto treeDataItemDto = new DgdTreeDataItemDto("hjTestList");
            treeDataList.add(treeDataItemDto);
        }
        dgdTaskRespDTO.setDgdTreeDataList(treeDataList);
        System.out.printf("任务ID为 %d 的“单轨吊测试任务”查询耗时 %d。", dataTaskId, (System.currentTimeMillis() - startTime));
        return dgdTaskRespDTO;
    }

    /**
     * 修改单轨吊数据
     *
     * @param dgdTaskReqDTO
     */
    @Override
    public int updateDetailDgd(DgdTaskReqDTO dgdTaskReqDTO) {
        return 0;
    }

    /**
     * 删除单轨吊数据，变更数据状态为2
     *
     * @param dataTaskId
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delAllDgdData(Long dataTaskId) {
        //测试数据基本信息
        //变更任务状态
        try {
            Long[] dataTaskIds = new Long[] {dataTaskId};
            dataTaskService.deleteDataTaskByDataTaskIds(dataTaskIds, "002");
        }catch (Exception e){
            e.printStackTrace();
        }
        //表面温度
        bmwdService.updateDataDgdBmwdByDataTaskId(dataTaskId);
        //环境
        hjService.updateDataDgdHjByDataTaskId(dataTaskId);
        //回绳轮预张紧力
        hshlService.updateDataDgdHshlByDataTaskId(dataTaskId);
        //角度
        jdService.updateDataDgdJdByDataTaskId(dataTaskId);
        //空动时间
        kdshjService.updateDataDgdKdshjByDataTaskId(dataTaskId);
        //空载向上制动减速度
        kzxshService.updateDataDgdKzxshByDataTaskId(dataTaskId);
        //冷却水
        lqshService.updateDataDgdLqshByDataTaskId(dataTaskId);
        //满载向下制动距离
        mzxxService.updateDataDgdMzxxByDataTaskId(dataTaskId);
        //排气温度
        pqwdService.updateDataDgdPqwdByDataTaskId(dataTaskId);
        //牵引力
        qylService.updateDataDgdQylByDataTaskId(dataTaskId);
        //速度
        sdService.updateDataDgdSdByDataTaskId(dataTaskId);
        //压力
        ylService.updateDataDgdYlByDataTaskId(dataTaskId);
        //制动力
        zhdlService.updateDataDgdZhdlByDataTaskId(dataTaskId);
        return 1;
    }

    /**
     * 单轨吊数据导入报告
     *
     * @param dgdReportData
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String dataDgdImportReport(DgdReportData dgdReportData) {
        // 报告模板名称
        String template = dgdReportData.getTempId();
        //测试任务信息
        DataTaskEntity dataTaskEntity = dataTaskService.selectDataTaskByDataTaskId(dgdReportData.getDataTaskEntity().getDataTaskId());
        dgdReportData.setDataTaskEntity(dataTaskEntity);
        //获取生成的工况图并转换png格式
        String rootPath = RuoYiConfig.getProfile() + RuoYiConfig.getChartPath() + "/";
        //空载向上图路径
        String kzxshImg = System.currentTimeMillis() + "-空载向上速度图.png";
        if(StringUtils.isNotEmpty(dgdReportData.getKzxshSdSvg())) {
            boolean res = ProcessPictureUtils.convertToPng(dgdReportData.getKzxshSdSvg(), rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" + kzxshImg);
            String resString = res ? "成功" : "失败";
            System.out.println("空载向上图导入:" + resString);
        }
        //满载向下图路径
        String mzxxImg = System.currentTimeMillis() + "-满载向下速度图.png";
        if(StringUtils.isNotEmpty(dgdReportData.getMzxxSdSvg())) {
            boolean res = ProcessPictureUtils.convertToPng(dgdReportData.getMzxxSdSvg(), rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" + mzxxImg);
            String resString = res ? "成功" : "失败";
            System.out.println("满载向下图导入:" + resString);
        }
        //满载向下图路径
        String jdImg = System.currentTimeMillis() + "-角度曲线图.png";
        if(StringUtils.isNotEmpty(dgdReportData.getJdSdSvg())) {
            boolean res = ProcessPictureUtils.convertToPng(dgdReportData.getMzxxSdSvg(), rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" + jdImg);
            String resString = res ? "成功" : "失败";
            System.out.println("角度曲线图导入:" + resString);
        }
        //速度减速分析曲线图路径
        String sdJsImg = System.currentTimeMillis() + "-速度减速分析曲线图.png";
        if(StringUtils.isNotEmpty(dgdReportData.getSdJsSdSvg())) {
            boolean res = ProcessPictureUtils.convertToPng(dgdReportData.getSdJsSdSvg(), rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" + sdJsImg);
            String resString = res ? "成功" : "失败";
            System.out.println("速度减速分析曲线图导入:" + resString);
        }
        //速度均速分析曲线图路径
        String sdJunsImg = System.currentTimeMillis() + "-速度均速分析曲线图.png";
        if(StringUtils.isNotEmpty(dgdReportData.getSdJunsSdSvg())) {
            boolean res = ProcessPictureUtils.convertToPng(dgdReportData.getSdJunsSdSvg(), rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" + sdJunsImg);
            String resString = res ? "成功" : "失败";
            System.out.println("速度均速分析曲线图导入:" + resString);
        }
        //速度曲线图路径
        String sdSdImg = System.currentTimeMillis() + "-速度曲线图.png";
        if(StringUtils.isNotEmpty(dgdReportData.getSdSdSvg())) {
            boolean res = ProcessPictureUtils.convertToPng(dgdReportData.getSdSdSvg(), rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" + sdSdImg);
            String resString = res ? "成功" : "失败";
            System.out.println("速度曲线图导入:" + resString);
        }
        // 曲线图的长宽
        int picW = 650;
        int picH = 210;
        //导入报告中
        Map<String, Object> params = new HashMap<>();
        //基本检测信息
        if(null != dgdReportData.getDataTaskEntity()) {
            params.put("受检单位", dgdReportData.getDataTaskEntity().getShjdw());
            params.put("设备名称", dgdReportData.getDataTaskEntity().getShbbh());
            params.put("主检姓名", dgdReportData.getDataTaskEntity().getZhjxm());
            params.put("测试人员", dgdReportData.getDataTaskEntity().getCshry());
            params.put("检测日期", DateUtils.dateTime(dgdReportData.getDataTaskEntity().getTaskCreateTime()));
        }
        //单轨吊参数
        List<Map<String, Object>> hjList = new ArrayList<>();
        List<Map<String, Object>> ylList = new ArrayList<>();
        List<Map<String, Object>> bmwdList = new ArrayList<>();
        List<Map<String, Object>> lqshList = new ArrayList<>();
        List<Map<String, Object>> pqwdList = new ArrayList<>();
        List<Map<String, Object>> hshlList = new ArrayList<>();
        List<Map<String, Object>> zhdlList = new ArrayList<>();
        List<Map<String, Object>> qylList = new ArrayList<>();
        List<Map<String, Object>> kdshjList = new ArrayList<>();
        if(null != dgdReportData.getDataDgdHjList() && !dgdReportData.getDataDgdHjList().isEmpty()) {
            //环境参数
            List<DataDgdHj> dataDgdHjs = dgdReportData.getDataDgdHjList();
            for(int i = 0 ; i < dataDgdHjs.size(); i++) {
                Map<String, Object> hjMap = new HashMap<>();
                hjMap.put("时间", DateUtils.dateTime(dataDgdHjs.get(i).getSaveTime()));
                hjMap.put("温度", StringUtils.isEmpty(dataDgdHjs.get(i).getWd()) ? "-" : dataDgdHjs.get(i).getWd());
                hjMap.put("湿度", StringUtils.isEmpty(dataDgdHjs.get(i).getShd()) ? "-" : dataDgdHjs.get(i).getShd());
                hjMap.put("大气压", StringUtils.isEmpty(dataDgdHjs.get(i).getDqy()) ? "-" : dataDgdHjs.get(i).getDqy());
                hjList.add(hjMap);
            }
        }
        if(null != dgdReportData.getDataDgdYlList() && !dgdReportData.getDataDgdYlList().isEmpty()) {
            //压力参数
            List<DataDgdYl> dataDgdYls = dgdReportData.getDataDgdYlList();
            for(int i = 0 ; i < dataDgdYls.size(); i++) {
                Map<String, Object> ylMap = new HashMap<>();
                ylMap.put("序号", String.valueOf(i + 1));
                ylMap.put("压力", StringUtils.isEmpty(dataDgdYls.get(i).getYali()) ? "-" : dataDgdYls.get(i).getYali());
                ylList.add(ylMap);
                ylService.updateDataDgdYl(dataDgdYls.get(i));
            }
        }
        if(null != dgdReportData.getDataDgdLqshList() && !dgdReportData.getDataDgdLqshList().isEmpty()) {
            //冷却水温度参数
            List<DataDgdLqsh> dataDgdLqshs = dgdReportData.getDataDgdLqshList();
            for(int i = 0 ; i < dataDgdLqshs.size(); i++) {
                Map<String, Object> lqshMap = new HashMap<>();
                lqshMap.put("序号", String.valueOf(i + 1));
                lqshMap.put("温度", StringUtils.isEmpty(dataDgdLqshs.get(i).getWendu()) ? "-" : dataDgdLqshs.get(i).getWendu());
                lqshList.add(lqshMap);
            }
        }
        if(null != dgdReportData.getDataDgdBmwdList() && !dgdReportData.getDataDgdBmwdList().isEmpty()) {
            //表面温度参数
            List<DataDgdBmwd> dataDgdBmwds = dgdReportData.getDataDgdBmwdList();
            for(int i = 0 ; i < dataDgdBmwds.size(); i++) {
                Map<String, Object> bmwdMap = new HashMap<>();
                bmwdMap.put("序号", String.valueOf(i + 1));
                bmwdMap.put("温度", StringUtils.isEmpty(dataDgdBmwds.get(i).getWendu()) ? "-" : dataDgdBmwds.get(i).getWendu());
                bmwdList.add(bmwdMap);
            }
        }
        if(null != dgdReportData.getDataDgdPqwdList() && !dgdReportData.getDataDgdPqwdList().isEmpty()) {
            //排气温度参数
            List<DataDgdPqwd> dataDgdPqwds = dgdReportData.getDataDgdPqwdList();
            for(int i = 0 ; i < dataDgdPqwds.size(); i++) {
                Map<String, Object> pqwdMap = new HashMap<>();
                pqwdMap.put("序号", String.valueOf(i + 1));
                pqwdMap.put("温度", StringUtils.isEmpty(dataDgdPqwds.get(i).getWendu()) ? "-" : dataDgdPqwds.get(i).getWendu());
                pqwdList.add(pqwdMap);
            }
        }
        if(null != dgdReportData.getDataDgdHshlList() && !dgdReportData.getDataDgdHshlList().isEmpty()) {
            //预张紧力参数
            List<DataDgdHshl> dataDgdHshls = dgdReportData.getDataDgdHshlList();
            for(int i = 0 ; i < dataDgdHshls.size(); i++) {
                Map<String, Object> hshlMap = new HashMap<>();
                hshlMap.put("序号", String.valueOf(i + 1));
                hshlMap.put("预张紧力", StringUtils.isEmpty(dataDgdHshls.get(i).getZdyzhjl()) ? "-" : dataDgdHshls.get(i).getZdyzhjl());
                hshlMap.put("比值", StringUtils.isEmpty(dataDgdHshls.get(i).getBizhi()) ? "-" : dataDgdHshls.get(i).getBizhi());
                hshlMap.put("测试时间", DateUtils.dateTime(dataDgdHshls.get(i).getSaveTime()));
                hshlList.add(hshlMap);
            }
            params.put("钢丝绳破断力",  StringUtils.isEmpty(dataDgdHshls.get(0).getGsshpdl()) ? "-" : dataDgdHshls.get(0).getGsshpdl());
        }
        if(null != dgdReportData.getDataDgdZhdlList() && !dgdReportData.getDataDgdZhdlList().isEmpty()) {
            //制动力参数
            List<DataDgdZhdl> dataDgdZhdls = dgdReportData.getDataDgdZhdlList();
            for(int i = 0 ; i < dataDgdZhdls.size(); i++) {
                Map<String, Object> zhdlMap = new HashMap<>();
                zhdlMap.put("序号", String.valueOf(i + 1));
                zhdlMap.put("制动力", StringUtils.isEmpty(dataDgdZhdls.get(i).getZhdl()) ? "-" : dataDgdZhdls.get(i).getZhdl());
                zhdlMap.put("测试时间", DateUtils.dateTime(dataDgdZhdls.get(i).getSaveTime()));
                zhdlList.add(zhdlMap);
            }
            params.put("额定制动力",  StringUtils.isEmpty(dataDgdZhdls.get(0).getEdzhdl()) ? "-" : dataDgdZhdls.get(0).getEdzhdl());
            params.put("总制动力",  StringUtils.isEmpty(dataDgdZhdls.get(0).getZzhdl()) ? "-" : dataDgdZhdls.get(0).getZzhdl());
            params.put("比值",  StringUtils.isEmpty(dataDgdZhdls.get(0).getBizhi()) ? "-" : dataDgdZhdls.get(0).getBizhi());
        }
        if(null != dgdReportData.getDataDgdQylList() && !dgdReportData.getDataDgdQylList().isEmpty()) {
            //牵引力参数
            List<DataDgdQyl> dataDgdQyls = dgdReportData.getDataDgdQylList();
            for(int i = 0 ; i < dataDgdQyls.size(); i++) {
                Map<String, Object> qylMap = new HashMap<>();
                qylMap.put("序号", String.valueOf(i + 1));
                qylMap.put("牵引力", StringUtils.isEmpty(dataDgdQyls.get(i).getQyl()) ? "-" : dataDgdQyls.get(i).getQyl());
                qylMap.put("测试时间", DateUtils.dateTime(dataDgdQyls.get(i).getSaveTime()));
                qylList.add(qylMap);
            }
            params.put("额定牵引力",  StringUtils.isEmpty(dataDgdQyls.get(0).getEdqyl()) ? "-" : dataDgdQyls.get(0).getEdqyl());
            params.put("平均牵引力",  StringUtils.isEmpty(dataDgdQyls.get(0).getPjqyl()) ? "-" : dataDgdQyls.get(0).getPjqyl());
            params.put("比值",  StringUtils.isEmpty(dataDgdQyls.get(0).getChzh()) ? "-" : dataDgdQyls.get(0).getChzh());
        }
        if(null != dgdReportData.getDataDgdKzxsh()) {
            //空载向上参数
            params.put("制动初速度",  StringUtils.isEmpty(dgdReportData.getDataDgdKzxsh().getZhdchsd()) ? "-" : dgdReportData.getDataDgdKzxsh().getZhdchsd());
            params.put("制动时间",  StringUtils.isEmpty(dgdReportData.getDataDgdKzxsh().getZhdshj()) ? "-" : dgdReportData.getDataDgdKzxsh().getZhdshj());
            params.put("制动减速度",  StringUtils.isEmpty(dgdReportData.getDataDgdKzxsh().getZhdjsd()) ? "-" : dgdReportData.getDataDgdKzxsh().getZhdjsd());
            params.put("空载向上曲线图", new PictureRenderData(picW, picH, rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" +kzxshImg));
            kzxshService.updateDataDgdKzxsh(dgdReportData.getDataDgdKzxsh());
        }
        if(null != dgdReportData.getDataDgdMzxx()) {
            //满载向下参数
            params.put("制动距离",  StringUtils.isEmpty(dgdReportData.getDataDgdMzxx().getZhdjl()) ? "-" : dgdReportData.getDataDgdMzxx().getZhdjl());
            params.put("制动初速度",  StringUtils.isEmpty(dgdReportData.getDataDgdMzxx().getZhdchsd()) ? "-" : dgdReportData.getDataDgdMzxx().getZhdchsd());
            params.put("6s运行距离",  StringUtils.isEmpty(dgdReportData.getDataDgdMzxx().getLmyxjl()) ? "-" : dgdReportData.getDataDgdMzxx().getLmyxjl());
            params.put("制动时间",  StringUtils.isEmpty(dgdReportData.getDataDgdMzxx().getZhdshj()) ? "-" : dgdReportData.getDataDgdMzxx().getZhdshj());
            params.put("满载向下曲线图", new PictureRenderData(picW, picH, rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" +mzxxImg));
            mzxxService.updateDataDgdMzxx(dgdReportData.getDataDgdMzxx());
        }
        if(null != dgdReportData.getDataDgdKdshjList() && !dgdReportData.getDataDgdKdshjList().isEmpty()) {
            //空动时间参数
            List<DataDgdKdshj> dataDgdKdshjs = dgdReportData.getDataDgdKdshjList();
            for(int i = 0 ; i < dataDgdKdshjs.size(); i++) {
                Map<String, Object> kdshjMap = new HashMap<>();
                kdshjMap.put("序号", String.valueOf(i + 1));
                kdshjMap.put("时间1", StringUtils.isEmpty(dataDgdKdshjs.get(i).getDkshj1()) ? "-" : dataDgdKdshjs.get(i).getDkshj1());
                kdshjMap.put("时间2", StringUtils.isEmpty(dataDgdKdshjs.get(i).getDkshj2()) ? "-" : dataDgdKdshjs.get(i).getDkshj2());
                kdshjMap.put("空动时间", StringUtils.isEmpty(dataDgdKdshjs.get(i).getKdshj()) ? "-" : dataDgdKdshjs.get(i).getKdshj());
                kdshjList.add(kdshjMap);
            }
        }
        if(null != dgdReportData.getDataDgdJd()) {
            //角度参数
            params.put("最大倾角",  StringUtils.isEmpty(dgdReportData.getDataDgdJd().getZdjd()) ? "-" : dgdReportData.getDataDgdJd().getZdjd());
            params.put("角度曲线图", new PictureRenderData(picW, picH, rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" +jdImg));
        }
        if(null != dgdReportData.getDataDgdSd()) {
            //速度减速分析参数
            params.put("平均减速度",  StringUtils.isEmpty(dgdReportData.getDataDgdSd().getJspjjs()) ? "-" : dgdReportData.getDataDgdSd().getJspjjs());
            params.put("减速时间",  StringUtils.isEmpty(dgdReportData.getDataDgdSd().getJsshj()) ? "-" : dgdReportData.getDataDgdSd().getJsshj());
            params.put("初速度",  StringUtils.isEmpty(dgdReportData.getDataDgdSd().getJschsd()) ? "-" : dgdReportData.getDataDgdSd().getJschsd());
            params.put("末速度",  StringUtils.isEmpty(dgdReportData.getDataDgdSd().getJsmsd()) ? "-" : dgdReportData.getDataDgdSd().getJsmsd());
            params.put("最大速度",  StringUtils.isEmpty(dgdReportData.getDataDgdSd().getJszdsd()) ? "-" : dgdReportData.getDataDgdSd().getJszdsd());
            params.put("最小速度",  StringUtils.isEmpty(dgdReportData.getDataDgdSd().getJszxsd()) ? "-" : dgdReportData.getDataDgdSd().getJszxsd());
            params.put("速度减速分析曲线图", new PictureRenderData(picW, picH, rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" +sdJsImg));
            //速度匀速分析参数
            params.put("平均速度",  StringUtils.isEmpty(dgdReportData.getDataDgdSd().getYspjsd()) ? "-" : dgdReportData.getDataDgdSd().getYspjsd());
            params.put("运行时间",  StringUtils.isEmpty(dgdReportData.getDataDgdSd().getYsshj()) ? "-" : dgdReportData.getDataDgdSd().getYsshj());
            params.put("速度匀速分析曲线图", new PictureRenderData(picW, picH, rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" +sdJunsImg));
            //速度参数
            params.put("最大运行速度",  StringUtils.isEmpty(dgdReportData.getDataDgdSd().getZdsd()) ? "-" : dgdReportData.getDataDgdSd().getZdsd());
            params.put("速度曲线图", new PictureRenderData(picW, picH, rootPath + dgdReportData.getDataTaskEntity().getDataTaskId() + "/" +sdSdImg));
            sdService.updateDataDgdSd(dgdReportData.getDataDgdSd());
        }
        params.put("空动时间数据List", kdshjList);
        params.put("牵引力数据List", qylList);
        params.put("制动力数据List", zhdlList);
        params.put("预张紧力数据List", hshlList);
        params.put("排气温度数据List", pqwdList);
        params.put("表面温度数据List", bmwdList);
        params.put("冷却水温度数据List", lqshList);
        params.put("压力数据List", ylList);
        params.put("环境数据List", hjList);
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-dgd.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }
}
